package ibmetp.mis.controller.bulletin;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.BulletinService;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.BulletinServiceImpl;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.Bulletin;
import ibmetp.mis.vo.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

public class BulletinUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public BulletinUpdateServlet() {
        super();
       
    }

	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("Calling BulletinUpdataServlet...");
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		
		//获取公告参数
		Bulletin bulletin = new  Bulletin();
		bulletin.setBulletinId(Long.valueOf(request.getParameter("bulletinId")));
		bulletin.setPublishMsg(request.getParameter("publishMsg"));
		User user=(User)request.getSession().getAttribute("userinfo");
		if(user!=null)
			bulletin.setPrincipal(user.getUserName());
		
		//更新公告
		BulletinService bl=new BulletinServiceImpl();		
		String result=bl.updateBulletin(bulletin);
		System.out.println(bulletin);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){			
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}

	}
}
